package utils;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 服务响应数据类。
 *
 * @param <T> 数据实体
 * @author guxiaojian
 * @since 1.0.0
 */
@Data
@NoArgsConstructor
public class ResponseData<T> {

    /**
     * 返回码
     */
    private String code = Code.SUCCESS;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    /**
     * ResponseData构造器
     *
     * @param code 返回码
     */
    public ResponseData(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public static <T> ResponseData<T> success(T data) {
        ResponseData<T> result = new ResponseData<T>();
        result.setData(data);
        return result;
    }

    /**
     * 返回码枚举类
     */
    public class Code {
        public final static String SUCCESS = "200";
        public final static String FAIl = "400";
        public final static String ERROR = "500";
    }

    /**
     * 返回信息枚举类
     */
    public class Message {
        public final static String PARAM_INVALID = "参数不合法";
        public final static String SERVER_ERROR = "服务器异常";
    }

}